package com.southminority.ethnic.controller.heritage;

import com.southminority.ethnic.common.result.PageResult;
import com.southminority.ethnic.common.result.R;
import com.southminority.ethnic.pojo.HeritageResearchLink;
import com.southminority.ethnic.service.heritage.HeritageResearchLinkService;
import com.southminority.ethnic.controller.heritage.vo.HeritageResearchLinkVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 非遗-研究成果关联控制器
 * 
 * @author SouthMinority
 */
@Tag(name = "非遗研究成果管理", description = "非遗项目相关研究成果的管理接口")
@Slf4j
@RestController
@RequestMapping("/api/heritage/research-links")
public class HeritageResearchLinkController {

    private final HeritageResearchLinkService researchLinkService;

    public HeritageResearchLinkController(HeritageResearchLinkService researchLinkService) {
        this.researchLinkService = researchLinkService;
    }

    // ====================================
    // 前端展示接口
    // ====================================

    @Operation(summary = "根据非遗项目ID获取相关研究成果", description = "前端展示用，获取指定非遗项目的相关研究成果列表")
    @GetMapping("/heritage/{heritageId}")
    public R<List<HeritageResearchLinkVO>> getResearchLinksByHeritageId(
            @Parameter(description = "非遗项目ID", required = true)
            @PathVariable Long heritageId) {
        try {
            List<HeritageResearchLinkVO> researchLinks = researchLinkService.getResearchLinksByHeritageId(heritageId);
            return R.ok(researchLinks);
        } catch (Exception e) {
            log.error("获取非遗项目相关研究成果失败, 非遗ID: {}", heritageId, e);
            return R.fail("获取相关研究成果失败: " + e.getMessage());
        }
    }


} 